<include file="Public:header"/>
<script type="text/javascript" src="__PUBLIC__/layer/laydate/laydate.js"></script>
<div id="main-content">
	<div id="top-alert" class="fixed alert alert-error" style="display: none;">
		<button class="close fixed" style="margin-top: 4px;">&times;</button>
		<div class="alert-content">警告内容</div>
	</div>
	<div id="main" class="main">
		<div class="main-title-h">
			<span class="h1-title"><a href="{:U('Article/adver')}">广告管理</a> >></span>
			<span class="h1-title"><empty name="data">添加广告<else/>编辑广告</empty></span>
		</div>
		<div class="tab-wrap">
			<div class="tab-content">
				<form id="form" action="{:U('Article/adverEdit')}" method="post" class="form-horizontal">
					<div id="tab" class="tab-pane in tab">
						<div class="form-item cf">
							<table>
								<tr class="controls">
									<td class="item-label">所属语言 :</td>
									<td>
										<select name="lang" class="form-control input-10x">
											<option value="">不区分语言</option>
											<volist name="__LANG__" id="v">
												<option value="{$key}"
												<eq name="data['lang']" value="$key">selected</eq>
												>{$v}</option>
											</volist>
										</select>
									</td>
									<td class="item-note"></td>
								</tr>
								<tr class="controls">
									<td class="item-label">图片标题 :</td>
									<td>
										<input type="text" class="form-control input-10x" name="name" value="{$data.name}">
									</td>
									<td class="item-note"></td>
								</tr>
								<tr class="controls">
									<td class="item-label">副标题描述 :</td>
									<td>
										<input type="text" class="form-control input-10x" name="subhead" value="{$data.subhead}">
									</td>
									<td class="item-note">选填</td>
								</tr>	
								<tr class="controls">
									<td class="item-label">图片链接 :</td>
									<td>
										<input type="text" class="form-control input-10x" name="url" value="{$data.url}">
									</td>
									<td class="item-note"></td>
								</tr>
								
								<tr class="controls">
									<td class="item-label">上传图片 :</td>
									<td>
										<div id="addpicContainer">
											<!-- 利用multiple="multiple"属性实现添加多图功能 -->
											<!-- position: absolute;left: 10px;top: 5px;只针对本用例将input隐至图片底下。-->
											<!-- height:0;width:0;z-index: -1;是为了隐藏input，因为Chrome下不能使用display:none，否则无法添加文件 -->
											<!-- onclick="getElementById('inputfile').click()" 点击图片时则点击添加文件按钮 -->
											<notempty name="data.img">
												<!--没有图片显示默认图片-->
												<img id="up_img" onclick="getElementById('inputfile').click()" style="cursor:pointer;max-width:500px;background-color:#000;" title="点击添加图片" alt="点击添加图片" src="/Upload/ad/{$data.img}">
												<else/>
												<!--没有图片显示默认图片-->
												<img id="up_img" onclick="getElementById('inputfile').click()" style="cursor:pointer;max-width:500px;" title="点击添加图片" alt="点击添加图片" src="__PUBLIC__/Admin/images/addimg.png">
											</notempty>
											<input type="hidden" id="img" name="img" value="{$data.img}">
											<input type="file" id="inputfile" style="height:0;width:0;z-index: -1; position: absolute;left: 10px;top: 5px;" value=""/>
										</div>
									</td>
									<td class="item-note">1920px*400px</td>
								</tr>
								
								<tr class="controls">
									<td class="item-label">图片显示位置 :</td>
									<td>
										<select name="look" class="form-control input-10x">
											<option value="0" <eq name="data.look" value="0">selected</eq>>电脑端</option>
											<option value="1" <eq name="data.look" value="1">selected</eq>>手机端</option>
										</select>
									</td>
									<td class="item-note"></td>
								</tr>
								
								
								<tr class="controls">
									<td class="item-label">显示上线时间 :</td>
									<td>
										<input type="text" class="form-control  input-10x " name="onlinetime" value="{$data['onlinetime']|addtime}" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
									</td>
									<td class="item-note">选填，目前只对轮播图显示效果</td>
								</tr>
								
								<eq name="data['addtime']" value=""><else/>
									<tr class="controls">
										<td class="item-label">添加时间 :</td>
										<td>
											<input type="text" class="form-control  input-10x " name="addtime" value="{$data['addtime']|addtime}" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
										</td>
										<td class="item-note"></td>
									</tr>
								</eq>
								<eq name="data['endtime']" value=""><else/>
									<tr class="controls">
										<td class="item-label">编辑时间 :</td>
										<td>
											<input type="text" class="form-control  input-10x " name="endtime" value="{$data['endtime']|addtime}" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
										</td>
										<td class="item-note"></td>
									</tr>
								</eq>
								
								<tr class="controls">
									<td class="item-label">排序 :</td>
									<td>
										<input type="text" class="form-control input-10x" name="sort" value="{$data.sort}">
									</td>
									<td class="item-note"></td>
								</tr>
								<tr class="controls">
									<td class="item-label">状态 :</td>
									<td>
										<select name="status" class="form-control input-10x">
											<option value="1" <eq name="data.status" value="1">selected</eq>>可用</option>
											<option value="0" <eq name="data.status" value="0">selected</eq>>禁用</option>
										</select>
									</td>
									<td class="item-note"></td>
								</tr>
								<tr class="controls">
									<td class="item-label"></td>
									<td>
										<div class="form-item cf">
											<button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">提交</button>
											<a class="btn btn-return" href="{$Think.server.HTTP_REFERER}">返 回</a>
											<notempty name="data.id"><input type="hidden" name="id" value="{$data.id}"/>
											</notempty>
										</div>
									</td>
								</tr>
							</table>
						</div>
					</div>
				</form>
				<script type="text/javascript">
					//提交表单
					$('#submit').click(function () {
						$('#form').submit();
					});
				</script>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$(document).ready(function () {
		//响应文件添加成功事件
		$("#inputfile").change(function () {
			//创建FormData对象
			var data = new FormData();
			//为FormData对象添加数据
			$.each($('#inputfile')[0].files, function (i, file) {
				data.append('upload_file' + i, file);
			});

			//发送数据
			$.ajax({
				url: '/Admin/Article/adverImage',
				type: 'POST',
				data: data,
				cache: false,
				contentType: false,		//不可缺参数
				processData: false,		//不可缺参数
				success: function (data) {
					if (data) {
						$('#up_img').attr("src", '/Upload/ad/' + $.trim(data));
						$('#img').val($.trim(data));
						$('#up_img').show();
					}
				},
				error: function () {
					alert('上传出错');
					$(".loading").hide();	//加载失败移除加载图片
				}
			});

		});
	});
</script>
<include file="Public:footer"/>
<block name="script">
	<script type="text/javascript" charset="utf-8">
		//导航高亮
		highlight_subnav("{:U('Article/adver')}");
	</script>
</block>